Okay, good morning everybody.
I hope you remember still what we discussed last week.
I'll briefly recap because this concept of object-oriented programming is probably the
one thing you underestimate, which is the essence of modern programming.
So making classes and objects in Python especially is very easy.
All you need to do is to write a class.
But why do we do this?
We want to wrap up things in dedicated objects.
We want to forget about them.
Okay?
We want to write them once and have everything wrapped up in one class.
So everything you do in Python in most languages will actually deal with objects and has everything
wrapped up within a class object.
So what do we want to do?
We want to of course do data abstraction.
We want to define some sort of internal representation.
This can be attributes, values or whatever you want to hold in there, some data and an
interface or some functions that help you to manipulate the data that's stored in the
class, in the object, but also that define how objects interact with each other.
Now, for example, compare two objects.
How do you define when two objects are the same or make one the other object or things
like that?
All of that you need to define.
Now, most of you would like to hide implementation details.
I showed you that example of how you would actually implement a linked list.
If you try to ever do this in low-level programming language like C, you'll see that's actually
a reasonably involved implementation to deal with all of these memory pointers and so on.
But actually you only want to do this once.
You want to hide this from other developers, from yourself in future at a point when you
are certain that the thing works more or less flawlessly.
So these are relatively simple things.
So you can rely on say the Python internal implementation of this sort of object.
But it's not like that this is something your computer would support out of the box.
There is no primitive data type that would allow you to do lists like that.
All of that needs to be programmed at some point.
But only ideally once.
Of course, you do it many times for many different kind of contexts, new languages and so on.
But when you use them and you only want to use data, you don't want to care about how
this is actually implemented.
In fact, this is not the way Python implements that.
Python actually uses a bit more sophisticated ways to represent a list.
So this bundling in a package is basically also what you use most of the time as a programmer.
Because if you sit in front of a new problem, you will not start from scratch.
You will probably start collecting things that help you doing these things.
Say you do something in geometry.
Well, then ideally you would try to find a number of classes, a package that already
provides you with geometric operations.
You have all of the education stuff and maybe even more advanced.
You don't want to implement all of these things yourself in your new program and define all
sorts of distances or whatever, starting from Pythagoras and doing all of these sort of
Presenters
Zugänglich über
Offener Zugang
Dauer
01:27:11 Min
Aufnahmedatum
2023-11-27
Hochgeladen am
2023-11-27 13:06:04
Sprache
en-US
classes and inheritance